package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.RolePermission;
import com.itheima.health.service.RolePermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("rolePermission")
public class RolePermissionController {

    @DubboReference
    private RolePermissionService rolePermissionService;

    @RequestMapping("findByRoleId")
    public Result findByRoleId(Integer id){
        List<RolePermission> rolePermissionList = rolePermissionService.findById(id);
        List<Integer> pIds = new ArrayList<>();
        for (RolePermission rolePermission : rolePermissionList) {
            pIds.add(rolePermission.getPermissionId());
        }

        if (pIds==null){
            return new Result(false, MessageConst.QUERY_PERMISSION_FAIL);
        }
        return new Result(true,MessageConst.QUERY_PERMISSION_SUCCESS,pIds);
    }
}
